/**
 * 后台管理，产品列表js 
 */

function initProdsTable(path,page){
	$.post(path+"productsAction_list.action",{
		"page":page
	},function(result){
		result=eval('('+result+')');
		$("#news_databody").empty();
		$("input[type=checkbox]").removeAttr("checked");
		if(result.rescode=='100'){  
			var prodsList=result.data;
			for(var i=0;i<prodsList.length;i++){
				var prod=prodsList[i];   
				var $e=$("<tr><td><input type='checkbox' value='"+prod.uuid+"' class='logch'></td><td>"+prod.uuid+"</td><td>"+prod.name+"</td><td>"+moment(prod.prodTime).format('20YY年MMMDo HH:mm')+"</td><td><a href='javascript:showproddetails(\""+path+"\",\""+prod.uuid+"\")' class='btn btn-warning'>查看详情</a><a href='javascript:editprod(\""+path+"\",\""+prod.uuid+"\")' class='btn btn-default' style='margin-left:10px;'>编辑</a></td></tr>");
				$("#news_databody").append($e); 
			}
			initPages(result.pagebean.curPage,result.pagebean.totalPages);
			  
		}else{
			alertError("操作失败"); 
		}
	});
}

function showproddetails(path,id){
	window.location.href="prodsadd.jsp?fr=show&id="+id; 
}
function editprod(path,id){
	window.location.href="prodsadd.jsp?fr=edit&id="+id; 
}

function delProds(path){
	$.post(path+"productsAction_del.action",{
		ids:getChecked()
	},function(result){
		result=eval('('+result+')');
		if(result.rescode=='100'){
			initProdsTable(path,1); 
			showSucMsg(result.msg);
		}else{
			showWarnMsg(result.msg);
		}
	});
}
 
/* 获取所有选中项的id字符串   */
function getChecked() {  
	var ids="";
	$("input[type=checkbox]").each(function() {
		if ($(this).prop("checked")) {
			ids+=$(this).val()+",";
		} 
	});
	return ids.substr(0,ids.length-1);
}